<!--我的待办-->
<!--我的待办-->
<!--我的待办-->
<template>
  <div class="content">
    <!--    头部区域-->
    <header>
      <div class="title">
        <p>我的待办（{{ myToDo.totalCount }}）</p>
        <div class="theUnderline"></div>
      </div>
      <div class="search">
        <el-dropdown @command="handleCommand">
          <span class="el-dropdown-link">
            {{ sourcePlatformData }}
            <el-icon :size="16"><CaretBottom /></el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu class="el-dropdown-menu1">
              <el-dropdown-item command="">全选</el-dropdown-item>
              <el-dropdown-item command="审计云">审计云</el-dropdown-item>
              <el-dropdown-item command="工程审计">工程审计</el-dropdown-item>
              <el-dropdown-item command="审计发现整改"
                >审计发现整改</el-dropdown-item
              >
            </el-dropdown-menu>
          </template>
        </el-dropdown>
        <div class="mt-4">
          <el-input v-model="workOrderNumber" placeholder="请输入工单编号">
            <template #append><div @click="search">搜索</div></template>
          </el-input>
        </div>
      </div>
    </header>
    <!--    内容区域-->
    <article>
      <div class="toDoLists">
        <div v-for="(item, index) in myToDo.toDoList" :key="index" class="item">
          <div>
            <span>来源平台:</span><span>{{ item.systemName }}</span>
          </div>
          <div>
            <span>工单编号:</span><span>{{ item.orderNumber }}</span>
          </div>
          <div>
            <span>到达时间:</span><span>{{ item.arrivalTime }}</span>
          </div>
          <div>
            <span>当前状态:</span><span>{{ item.status }}</span>
          </div>
          <div class="toView"><a :href="item.link">查看</a></div>
        </div>
      </div>

      <!--      分页区域-->
      <div class="footer" v-if="myToDo.totalCount !== 0">
        <div class="title">
          每页12条数据，当前第{{ theCurrentNumberOfPages }}页，共{{
            totalNumberOfPages
          }}页
        </div>
        <div class="page">
          <el-pagination
            :page-size="pageSize"
            background
            layout="prev, pager, next, jumper,slot"
            :total="myToDo.totalCount"
            prev-text="上一页"
            next-text="下一页"
            @current-change="handleCurrentChange"
            :current-page="theCurrentNumberOfPages"
          >
            <template #default>
              <button class="btn">确定</button>
            </template>
          </el-pagination>
        </div>
      </div>
    </article>
    <!--      无数据-->
    <div class="noData" v-if="myToDo.totalCount === 0">
        <div class="iconImg">
            <img src="@/assets/img/zwsj.png" alt="">
            <div class="title">暂无数据！</div>
        </div>
    </div>
  </div>
</template>

<script setup>
import { CaretBottom } from "@element-plus/icons-vue";
import { ref, computed } from "vue";
import useMyToDo from "@/stores/myToDo.js";
import { toDoList } from "@/api/index.js";
const myToDo = useMyToDo();
// 用户输入工单编号
const workOrderNumber = ref("");
//每页数据条目数
const pageSize = ref(12);
// 当前页数
const theCurrentNumberOfPages = ref(1);
// 总页数
const totalNumberOfPages = computed(() => {
  return Math.ceil(myToDo.totalCount / pageSize.value);
});

//来源平台
const sourcePlatform = ref("");

// 请求待办参数
const requestToDoParameter = () => {
  return {
    type: "task",
    systemName: sourcePlatform.value,
    keyword: workOrderNumber.value,
    pageSize: pageSize.value,
    pageNum: theCurrentNumberOfPages.value,
  };
};
//请求待办别表
const request = async () => {
  const toDo = await toDoList(requestToDoParameter());
  myToDo.toDoList = toDo.jsonArray;
};
request();
const sourcePlatformData = ref("来源平台");
//来源平台选择
const handleCommand = async (value) => {
  sourcePlatformData.value = value === "" ? "全选" : value;
  sourcePlatform.value = value;
  await request();
  theCurrentNumberOfPages.value = 1;
};

// 自定义页数
const handleCurrentChange = async (number) => {
  theCurrentNumberOfPages.value = number;
  await request();
};
// 搜索
const search = async () => {
  await request();
  workOrderNumber.value = "";
  theCurrentNumberOfPages.value = 1;
};
</script>

<style scoped lang="less">
.content {
  background: #ffffff;
  border-radius: 12px;
  max-width: 1400px;
  margin: 20px auto 0 auto;
  position: relative;
  header {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    margin-bottom: 20px;

    .title {
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      width: 132px;

      p {
        font-size: 18px;
        color: #303133;
        font-weight: 700;
        margin-block-start: 0;
        margin-block-end: 0;
      }

      .theUnderline {
        height: 4px;
        background-color: #375efa;
        border-radius: 2px;
      }
    }

    .search {
      display: flex;
      align-items: center;
      .el-dropdown-link {
        font-size: 18px;
        color: #606266;
        font-weight: 500;
      }

      .mt-4 {
        margin-left: 64px;

        .el-input-group {
          height: 48px;

          :deep(.el-input__wrapper) {
            background: #f7f9ff;
            width: 290px;
          }

          :deep(.el-input-group__append) {
            width: 51px;
            background-color: #375efa;
            font-size: 16px;
            color: #ffffff;
            font-weight: 700;
            cursor: pointer;
          }
        }
      }
    }
  }
  article {
    max-width: 1400px;
    width: 1400px;
    height: 720px;
    position: relative;
    .toDoLists {
      display: grid;
      justify-content: space-between;
      grid-template-columns: repeat(auto-fill, 326px);
      gap: 16px;
      margin: 0 16px;
      box-sizing: border-box;
      .item {
        width: 326px;
        height: 192px;
        margin-bottom: 16px;
        padding: 24px 16px 24px 16px;
        box-sizing: border-box;
        background: #fafbfc;
        border: 1px solid #dddddd;
        border-radius: 4px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        div {
          span {
            font-size: 14px;
            color: #303133;
            font-weight: 500;
          }

          span:nth-child(1) {
            margin-right: 12px;
          }
        }

        .toView {
          font-size: 16px;
          color: #375efa;
          cursor: pointer;
        }
      }
      .item:hover {
        box-shadow: 0 0 12px 0 rgba(0, 0, 0, 0.12);
      }
    }
    .footer {
      width: 95%;
      margin: 24px 2% 40px 2%;
      bottom: 0;
      display: flex;
      justify-content: space-between;
      position: absolute;
      .title {
        font-size: 12px;
        color: #909399;
        font-weight: 400;
      }

      .page {
        :deep(.el-pagination__goto) {
          display: none;
        }

        .btn {
          width: 76px;
          background-color: #375efa;
          font-size: 16px;
          color: #ffffff;
        }
      }
    }
  }
  .noData {
    position: absolute;
    margin: auto;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    .iconImg{
      text-align: center;
      img{
        width: 200px;
      }
      .title{
          font-size: 20px;
      }
    }

  }
}
</style>
